class Solution
{
public:
    string findLexSmallestString(string s, int a, int b)
    {
        int n = s.size();
        auto addOdd = [&]()
        {
            for (int i = 1; i < n; i += 2)
            {
                int digit = s[i] - '0';
                digit = (digit + a) % 10;
                s[i] = digit + '0';
            }
        };

        auto addEven = [&]()
        {
            for (int i = 0; i < n; i += 2)
            {
                int digit = s[i] - '0';
                digit = (digit + a) % 10;
                s[i] = digit + '0';
            }
        };

        auto shift = [&]()
        {
            rotate(s.rbegin(), s.rbegin() + b, s.rend());
        };

        string result = s;
        for (int l = 0; l < n; ++l)
        {
            for (int i = 0; i < 10; ++i)
            {
                addOdd();
                if ((b & 1))
                {
                    for (int j = 0; j < 10; ++j)
                    {
                        addEven();
                        result = min(result, s);
                    }
                }
                else
                {
                    result = min(result, s);
                }
            }
            shift();
        }

        return result;
    }
};